package com.hyperboost.controller;

import com.hyperboost.constant.MessageConstant;
import com.hyperboost.dto.ShareDTO;
import com.hyperboost.dto.SharePageQueryDto;
import com.hyperboost.result.PageResult;
import com.hyperboost.result.Result;
import com.hyperboost.service.ShareService;
import com.hyperboost.vo.ShareVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分享相关接口
 */
@RestController
@RequestMapping("/frontend/share")
@Slf4j
public class ShareController {
    @Autowired
    private ShareService shareService;


    /**
     * 发布分享
     *
     * @param shareDTO
     * @return
     */
    @PostMapping("/add")
    public Result shareAdd(@RequestBody ShareDTO shareDTO) {
        log.info("发布分享：{}", shareDTO);
        shareService.shareAdd(shareDTO);
        return Result.success(MessageConstant.SHARE_ADD_SUCCESS);
    }

    /**
     * 删除分享
     *
     * @param shareId
     */
    @DeleteMapping("/delete/{shareId}")
    public Result deleteShare(@PathVariable Long shareId) {
        log.info("删除分享：{}", shareId);

        return shareService.deleteShare(shareId);
    }

    /**
     * 分页查询分享列表
     *
     * @param sharePageQueryDto
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<ShareVo>> pageShare(SharePageQueryDto sharePageQueryDto) {
        PageResult<ShareVo> shareVos = shareService.pageShare(sharePageQueryDto);

        return Result.success(shareVos);
    }

    /**
     * 分页查寻用户自己发布的分享列表
     *
     * @param sharePageQueryDto
     * @return
     */
    @GetMapping("/page/byuser")
    public Result<PageResult<ShareVo>> pageShareByUserId(SharePageQueryDto sharePageQueryDto) {

        PageResult<ShareVo> shareVos = shareService.pageShareByUserId(sharePageQueryDto);
        return Result.success(shareVos);
    }

    /**
     * 根据标签Id查询分享列表
     *
     * @param noticeId
     * @return
     */
    @GetMapping("/notice/{noticeId}")
    public Result<List<ShareVo>> getShareByNoticeId(@PathVariable Long noticeId) {
        List<ShareVo> shareVos = shareService.getShareByNoticeId(noticeId);

        return Result.success(shareVos);
    }

    /**
     * 根据分享Id查询分享详情
     *
     * @param shareId
     * @return
     */
    @GetMapping("/share/{shareId}")
    public Result<ShareVo> getShareById(Long shareId) {
        ShareVo shareVo = shareService.getShareByShareId(shareId);
        return Result.success(shareVo);
    }
}
